import { Injectable } from '@nestjs/common'
import { CreateStarDto } from './dto/create-star.dto'

import { PrismaService } from 'src/common/prisma/prisma.service'

@Injectable()
export class StarService {
   constructor(private readonly prisma: PrismaService) {}
   async create(createStarDto: CreateStarDto, userId: number) {
      return await this.prisma.star.create({
         data: {
            user: { connect: { id: userId } },
            artiel: { connect: { id: +createStarDto.articleId } }
         }
      })
   }

   async findOne(articleId: number, userId: number) {
      return await this.prisma.star.findFirst({
         where: { userId: +userId, AND: { articelId: +articleId } },
         include: {
            user: true
         }
      })
   }

   async remove(id: number) {
      return await this.prisma.star.delete({
         where: { id }
      })
   }

   async getStarList(userId: number) {
      return await this.prisma.star.findMany({
         where: { userId },
         include: {
            artiel: true
         }
      })
   }
}
